package hyy_2022;

import java.util.Arrays;

/**
 * 有序数组的平方
 */
public class _0906_977_SqrtSortArray {
    /**
     * 最简单的方法:将数组nums中的数平方后直接排序
     * @param nums
     * @return int[]
     */
    public int[] sortedSquares(int[] nums) {
        int[] ans = new int[nums.length];
        for(int i=0;i<nums.length;i++) {
            ans[i] = nums[i] * nums[i];
        }
        Arrays.sort(ans);
        return ans;
    }

    public static void main(String[] args) {
        // You can't specify target table 'ATM' for update in FROM clause
        //delete from test AS ATM WHERE NOT EXISTS (SELECT * FROM test AS IBM WHERE ATM.id1 = IBM.id2 AND ATM.id3 = IBM.id4 AND ATM.id5 = IBM.id6)
        String sql = "delete from test AS ATM WHERE NOT EXISTS (SELECT * FROM test AS IBM WHERE ATM.id1 = IBM.id2 AND ATM.id3 = IBM.id4 AND ATM.id5 = IBM.id6)";
        String specify = substringBetween("You can't specify target table 'ATM' for update in FROM clause", "You can't specify target table '", "' for update in FROM clause");
        sql = sql.toUpperCase();
        sql = sql.replaceFirst("TEST\\s+(AS)?\\s+" +  specify,"TEST_01 AS " + specify);
        System.out.println( "delete".indexOf("de"));
    }

    public static String substringBetween(final String str, final String open, final String close) {
        if (str == null || open == null || close == null) {
            return null;
        }
        final int start = str.indexOf(open);
        if (start != -1) {
            final int end = str.indexOf(close, start + open.length());
            if (end != -1) {
                return str.substring(start + open.length(), end);
            }
        }
        return null;
    }


}
